using System;
using System.Collections.Generic;
using System.Text;

namespace FROG
{
    public class CodeSnippet
    {
        public CodeSnippet()
        {
        }

        public CodeSnippet(string shortcut, string code) : this(shortcut, code, "$", false)
        {
        }

        public CodeSnippet(string shortcut, string code, string delimiter, bool isSurroundsWith)
        {
            this.Shortcut = shortcut;
            this.Code = code;
            this.Delimiter = delimiter;
            this.IsSurroundsWith = isSurroundsWith;
        }

        private string _code;

        public string Code
        {
            get { return _code; }
            set { _code = value; }
        }

        private string _delimiter;

        public string Delimiter
        {
            get { return _delimiter; }
            set { _delimiter = value; }
        }

        private bool _isSurroundsWith;

        public bool IsSurroundsWith
        {
            get { return _isSurroundsWith; }
            set { _isSurroundsWith = value; }
        }

        private string _shortcut;

        public string Shortcut
        {
            get { return _shortcut; }
            set { _shortcut = value; }
        }


        public static explicit operator CodeSnippet(ScintillaNet.Snippet snippet)
        {
            CodeSnippet codeSnippet = new CodeSnippet();
            codeSnippet.Code = snippet.Code;
            codeSnippet.Delimiter = snippet.Delimeter.ToString();
            codeSnippet.IsSurroundsWith = snippet.IsSurroundsWith;
            codeSnippet.Shortcut = snippet.Shortcut;
            return codeSnippet;
        }

        public static explicit operator ScintillaNet.Snippet(CodeSnippet codeSnippet)
        {
            char delimiter = '$';
            if (!string.IsNullOrEmpty(codeSnippet.Delimiter))
                delimiter = codeSnippet.Delimiter[0];
            ScintillaNet.Snippet snippet = new ScintillaNet.Snippet(codeSnippet.Shortcut, codeSnippet.Code, delimiter, codeSnippet.IsSurroundsWith);
            return snippet;
        }
    }
}